package com.shoppingmall.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.shoppingmall.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * 2020/3/14
 * 描述：
 */
public class TipDialog extends BasePopupWindow {

    private TextView contentTv, cancelTv, confirmTv;
    private OnSureClickListener onSureClickListener;

    public TipDialog(Context context) {
        super(context);
        setPopupGravity(Gravity.CENTER);
        setOutSideTouchable(false);
        contentTv = findViewById(R.id.tv_content);
        cancelTv = findViewById(R.id.tv_cancel);
        confirmTv = findViewById(R.id.tv_confirm);
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.dialog_tip);
    }


    public void setContentTv(String content) {
        contentTv.setText(content);
    }


    private void initEvent() {
        cancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        confirmTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != onSureClickListener)
                    onSureClickListener.confirm();
            }
        });
    }

    public void setOnSureClickListener(OnSureClickListener onSureClickListener) {
        this.onSureClickListener = onSureClickListener;
    }

    public interface OnSureClickListener {
        void confirm();
    }
}
